package com.imooc.grace.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

public class Sample {

    // 签名名称
    private static String signName ="华夏招聘网";
    // 模板code
    private static String templateCode ="SMS_472315318";
    // AccessKey ID
    private static String ACCESS_KEY_ID = "LTAI5t8qYaPyE1dDS2pw5Pc6";
    //AccessKey Secret
    private static String ACCESS_KEY_SECRET ="Dm3gGv3LN0gI9Zcw0iBpHh8vWN7Kua";

    public static Client createClient() throws Exception {
        Config config = new Config();
        config.accessKeyId = ACCESS_KEY_ID;
        config.accessKeySecret = ACCESS_KEY_SECRET;
        return  new Client(config);
    }


    public static SendSmsResponse sendSms(String phoneNumber,String  code) throws Exception {
        Client client = createClient();
        SendSmsRequest sendReq = new SendSmsRequest()
                .setPhoneNumbers(phoneNumber)
                .setSignName(signName)
                .setTemplateCode(templateCode)
                .setTemplateParam("{\"code\": \"" + code+ "\"}");
        SendSmsResponse sendResp =client.sendSms(sendReq);
        return sendResp;
    };



}
